import Http from "../utils/http";
import Base from "./base";

class Service extends Base{
 
  /**
   *  分页获取服务列表
   *  page 页码
   *  count 每页数量
   *  category_id 分类 id
   *  type 服务类型
  */
  async getServiceList(category_id=null,type=null){ 
        
    if(!this.hasMoreData){
      return this.data
    }

     const serviceList = await Http.request({
        url:'v1/service/list',
        data:{
          page:this.page,
          count:this.count,
          category_id: category_id || '' ,
          type:type || ''
        } 
     }); 
       // 数据合并
       this.data = this.data.concat(serviceList.data)
       this.hasMoreData = !(this.page === serviceList.last_page)
       this.page++
       return this.data;
  }

  static getServiceById(serviceId){
    return Http.request({
      url: `v1/service/${serviceId}`
    })
  }

  static updateServiceStatus(serviceId,action){
      return Http.request({
        url:`v1/service/${serviceId}`,
        data:{
          action
        },
        method:"POST"
      })
  }

  static   publishService(data) {
    return   Http.request({
        url: 'v1/service',
        data,
        method: 'POST'
    })
  }

  // 获取服务状态
  static getServiceStatus(type){
    // return Http.request({
    //   url: `v1/service/count?type=${type}`
    // })
    console.log('获取服务状态');
  }
  
}
  

export default Service